package bo;

import IBO.IZoneGeographique;
import boerrors.ZoneInexistantException;
import dao.AbstractFactory;
import dao.dto.ZoneDto;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
import util.Util;

public class Zone implements IZoneGeographique,Serializable,Cloneable{
        private int _idZone;
        private String _libelleZone;

	//*******************************************************************
	//Constructeurs
	//*******************************************************************
        
        public Zone(ZoneDto zoneDto) throws RemoteException{
                setIdZone(zoneDto.getIdZone());
                setLibelleZone(zoneDto.getLibelleZone());
                UnicastRemoteObject.exportObject(this,0);
        }
        
        public Zone(int idZone, String libelleZone) throws RemoteException {
		setIdZone(idZone);		
                setLibelleZone(libelleZone);
                UnicastRemoteObject.exportObject(this,0);
        }

	//*******************************************************************
        //Convertir bo - dto
	//*******************************************************************

        public ZoneDto creerZoneDto() throws RemoteException {
                return new ZoneDto(this.getIdZone(), this.getLibelleZone());
        }
        
	//*******************************************************************
	//Setters
	//*******************************************************************
        
        public synchronized void setIdZone(int idZone) {
		Util.checkPositive(idZone);
                this._idZone = idZone;
	}
	
        public synchronized void setLibelleZone(String libelleZone) {
		Util.checkString(libelleZone);
                this._libelleZone = libelleZone;
	}
        
	//*******************************************************************
	//Getters
	//*******************************************************************
	
        public synchronized int getIdZone() throws RemoteException{
		return _idZone;
	}
	
        public synchronized String getLibelleZone() throws RemoteException{
		return _libelleZone;
	}

        //*******************************************************************
	//Methodes static
	//*******************************************************************
        
        public synchronized static Vector<IZoneGeographique> lister() throws ZoneInexistantException, RemoteException{
                Vector<ZoneDto> listeZoneDto = AbstractFactory.getInstance().getZoneDao().lister();
                Vector<IZoneGeographique> listeZone = new Vector<IZoneGeographique>();
                for(int i = 0; i < listeZoneDto.size(); i++){
                    ZoneDto zoneDto = listeZoneDto.get(i);
                    listeZone.add(new Zone(zoneDto));
                }
                return listeZone;
        }

        //*******************************************************************
	//Methodes clonable
	//*******************************************************************        
        
        @Override
        public Object clone(){
                Zone zone = null;
                try {
                    zone = (Zone) super.clone();
                } catch (CloneNotSupportedException ex) {
                    ex.printStackTrace(System.err);
                }
                return zone;
        }         
}